import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
		sidebarItemIndex: 0,//分类左侧侧边栏index
		categoryIndex: 0,// 分类页下标
		DetailPageData: {},// 详情页数据
		shoppingData: [],// 购物车数据
	
    },
    getters: {
		getCategoryIndex(state) {
			return state.categoryIndex
		},
		getSidebarItemIndex(state) {
			return state.sidebarItemIndex
		},
		getShoppingData(state) {
			return state.shoppingData
		},
    },
    mutations: {
		// 设置分类页下标
		setCategoryIndex(state, index) {
			state.categoryIndex = index
		},
		
	  
		setSidebarItemIndex(state, index) {
			state.sidebarItemIndex = index
		},
		// 设置详情页数据
		setDetailPageData(state, item) {
			state.DetailPageData = item
		},
		 // 设置购物车数据
		 setShoppingData(state, item) {
			state.shoppingData.push(item)
			state.shoppingData = Array.from(new Set(state.shoppingData))
			console.log(state.shoppingData);
		},
	  
    },
    actions: {
    },
    modules: {
    }
})
